String.prototype.startWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length){
 		 return false;
 	}
	if(this.substr(0,str.length)==str){
  		return true;
  	}else{
  		return false;
  	}
	return true;
}


function isChn(str){
	var reg = /^[u4E00-u9FA5]+$/;
	if(!reg.test(str)){
		return false;
	}
	return true;
}

function isNormal(str){
	var reg = /^[^\f\n\r\t\v]+$/;
	if(!reg.test(str)){
		return false;
	}
	return true;
}

function isName(str){
	var reg = /^(?!_-)(?!.*?_-$)[a-zA-Z0-9_\u3001\u4e00-\u9fa5-]+$/;
	if(!reg.test(str)){
		return false;
	}
	return true;
}

function isPassword(str){
	var reg = /^(\w){6,16}$/;
	if(!reg.test(str)){
		return false;
	}
	return true;
}

function isPostcode(str){
	var reg = /^[a-zA-Z0-9]{3,12}$/;
	if(!reg.test(str)){
		return false;
	}
	return true;
}

function isDate(str){
	var reg = /^([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))$/;
	if(!reg.test(str)){
		return false;
	}
	return true;
}


jQuery.validator.addMethod("isLoginId", function(value,element) {
		var reg = /^(?!_)(?!.*?_$)[a-zA-Z0-9_]+$/;
		return this.optional(element) || (reg.test(value));
	}, "格式不正确<br>"
); 
jQuery.validator.addMethod("isName", function(value,element) {
		var reg = /^(?!_-)(?!.*?_-$)[a-zA-Z0-9_\u4e00-\u9fa5\-]+$/;
		return this.optional(element) || (reg.test(value));
	}, "格式不正确<br>"
); 
jQuery.validator.addMethod("isPassword", function(value,element) {
		var reg = /^[a-zA-Z0-9]+$/;
		return this.optional(element) || (reg.test(value));
	}, "格式不正确<br>"
); 
jQuery.validator.addMethod("isNormal", function(value,element) {
		//var reg = /^([a-zA-Z0-9\u4e00-\u9fa5]+)[a-zA-Z0-9_(-)!.,;:\u4e00-\u9fa5]*$/;
		var reg = /^[^\x27\x22]+$/;
		return this.optional(element) || (reg.test(value));
	}, "<br>只允许输入汉字、数字、中文标点符号<br>"
); 

jQuery.validator.addMethod("isID", function(value,element) {
		
			return IdCardValidate(value);
		}, "<br>无效的身份证号码<br>"
	); 

function buildSelect(data){
	
	var str= '<select>';
	try{
		var obj=$.parseJSON(data.responseText);
		$.each(obj,function(n,v){
			str+='<option value='+n+'>'+v+'</option>';
		});
	}catch(e){
		alert(e)
	}
	str+='</select>';
	return str;
}	

// Client-Side Common functions//

function SearchSupplier(SupplierID,SupplierName,StatusID,StatusName,TypeID){
	window.open ("SupplierSearch.aspx?FormName=ServerForm&TypeID=" + TypeID + "&SupplierID=" + SupplierID + "&SupplierName=" + SupplierName + "&StatusID=" + StatusID + "&StatusName=" +StatusName ,"","width=700,height=600,top=100,left=100,scrollbars=true,titlebar=true,resizable=true");
}

function SearchMaterial(MaterialID,MaterialNo,MaterialName,SpecsID,SpecsName,UnitName,StockQuantity,Price){
	window.open ("MaterialSearch.aspx?FormName=ServerForm&MaterialID=" + MaterialID + "&MaterialNo=" + MaterialNo + "&MaterialName=" + MaterialName + "&SpecsID=" + SpecsID + "&SpecsName=" + SpecsName + "&UnitName=" + UnitName + "&StockQuantity=" + StockQuantity + "&Price=" + Price,"","width=700,height=600,top=100,left=100,scrollbars=false,titlebar=false,resizable=false");
}
function SearchMaterialSupplier(ctlMaterialID,SupplierID,SupplierName,Price){
	ctl=eval("document.ServerForm." + ctlMaterialID);
	nNoPass=parseInt(ctl.value);
	if (isNaN(nNoPass))
	{
		return;
	}
	if(nNoPass > 0)
	{
		window.open ("SearchForPurchase.aspx?FormName=ServerForm&ID=" + ctl.value + "&SupplierID=" + SupplierID + "&SupplierName=" + SupplierName + "&Price=" + Price,"","width=600,height=600,top=100,left=100,scrollbars=true,titlebar=true,resizable=true");
	}
}
function ConfirmDelete(sDeleteObjectName)
{
	return confirm("你确认删除"+sDeleteObjectName+"吗?");
}
function ConfirmCancel(sDeleteObjectName)
{
	return confirm("你确认取消 "+sDeleteObjectName+"吗?");
}
function ConfirmClose()
{
	return confirm("你确认关闭此项申请吗?");
}
function ConfirmFailure()
{
	return confirm("你确认此次招标为失败吗?");
}
//confirm Undo 
function ConfirmUndo(sDeleteObjectName)
{
	return confirm("Are you sure to undo "+ sDeleteObjectName+" ?");
}

function ShowNewWindow(sFileName)
{
	 window.open(sFileName,"","width=1024,height=768,top=0,left=0,toolbars=no,scrollbars=yes,status=yes,resizable=yes,title=no,location=no");
}
function ShowNewWindow1(sFileName)
{
	 window.open(sFileName,"","width=825,height=810,top=0,left=0,toolbars=no,scrollbars=yes,status=yes,resizable=yes,title=no,location=no");
}
function ShowNewWindow2(sFileName)
{
	 window.open(sFileName,"","width=500,height=600,top=0,left=0,toolbars=no,scrollbars=yes,status=yes,resizable=yes,title=no,location=no");
}	
function ShowNewWindow3(sFileName)
{
	 window.open(sFileName,"","width=550,height=600,top=0,left=0,toolbars=no,scrollbars=yes,status=yes,resizable=yes,title=no,location=no");
}
function OpenWindow(sFileName)
{
	window.open(sFileName)
}	
function OpenShoppingCart(sProductID)
{
	 window.open("ShoppingCart.aspx?ProductID=" + sProductID,"ShoppingCart","width=750,height=600,top=0,left=0,toolbars=no,scrollbars=yes,status=yes,resizable=yes,title=no,location=no");
}	
function OpenHistoryWindow(sFileName)
{
	window.open(sFileName,"","width=700,height=500,top=100,left=100,toolbars=no,scrollbars=no,status=no,resizable=no");
}	
function OpenSmallWindow(sFileName)
{
	window.open(sFileName,"","width=500,height=300,top=100,left=100,toolbars=no,scrollbars=no,status=no,resizable=no");	
}
function OpenDetailsWindow(sFileName)
{
	window.open(sFileName,"","width=480,height=250,top=100,left=100,toolbars=no,scrollbars=no,status=no,resizable=no");	
}
function GetDate(CtrlName,CurDate)    
{   
	ctl=eval("document.forms[0]." + CtrlName);
	if (!ctl.readOnly)
		ChildWindow = window.open('../Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName + '&CurDate=' + CurDate, "PopUpCalendar", "width=325,height=300,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");   
 }   
 
 function GetDateTime(CtrlName,CurDate)    
{  
	ctl=eval("document.forms[0]." + CtrlName);
	if (!ctl.readOnly)
		ChildWindow = window.open('../CalendarTime.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName + '&CurDate=' + CurDate, "PopUpCalendar", "width=390,height=300,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");   
 }   
 
 function SetAll(){
	fm=document.ServerForm ;
	if (fm.chkAll.checked)
		bCheck=true;
	else
		bCheck=false;
		
	for(i=0;i<fm.elements.length;i++)
	   if (fm.elements[i].type=="checkbox")
	      if(fm.elements[i].id.indexOf("chkSelect")!=-1)
			fm.elements[i].checked=bCheck;    
}
			
function CheckSelect(){
	fm=document.ServerForm ;
	for(i=0;i<fm.elements.length;i++)
	   if (fm.elements[i].type=="checkbox")
			if (fm.elements[i].checked && fm.elements[i].id.indexOf("chkSelect")!=-1)
				   return true;
  
	alert("Please select at least one item!");
	return false;		   
}


function ConfirmSave(){
	return confirm("Are you sure to save the content?");
}

function ConfirmUpdate(sObject){
	return confirm("Are you sure to resubmit the " + sObject + "?");
}

function HasDoubleByte(s){
	for(i=0;i<s.length;i++){
	   n=s.charCodeAt(i);
	   if(n<0 || n>=127)
	      return true;
	}  
	return false;
}

function OpenAttach(ctl,tp,multi){
   s=eval("document.ServerForm." + ctl + ".value");
   window.open ("AttachFile.aspx?Control=" + ctl + "&Type=" + tp + "&Multi=" + multi + "&FileList=" + s ,"","width=650,height=400,scrollbars=yes,titlebar=false,status=yes")
}

function ShowAlert(sHint)
{
	alert(sHint);
}
			  
function hidestatus(){
	window.status="";
	return true;
}

function FindPartner(ctlPartnerID,psRelation)
{
	window.open("../General/FindPartner.aspx?Relation=" + psRelation + "&ctlPartnerID=" + ctlPartnerID,"","width=800,height=600,toolbars=no,scrollbars=yes,status=yes,resizable=no")
}

 function GetPartID(CtrlName1,Multi,IsPager)//(控件ID，是否多行选中，是否分页)
 {
    window.open("../General/FindPart.aspx?ctlPartID=" + CtrlName1 + "&Multi=" + Multi + "&IsPager=" + IsPager ,"","width=855,height=600,toolbars=no,scrollbars=yes,status=yes,resizable=no");   
 }

String.prototype.trim= function(){  
    // 用正则表达式将前后空格  
    // 用空字符串替代。  
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}

function StringBuffer() {

   this.buffer = [];

 }

 

 StringBuffer.prototype.append = function append(string) {

   this.buffer.push(string);

   return this;

 };

 

 StringBuffer.prototype.toString = function toString() {

   return this.buffer.join("");

 }; 
